package br.com.unifebe.tcc.DAO;

import java.util.Collection;

import org.hibernate.Transaction;
import org.hibernate.classic.Session;
import org.hibernate.criterion.Restrictions;

import br.com.unifebe.tcc.UTILS.HibernateUtils;
import br.com.unifebe.tcc.model.Venda;
import br.com.unifebe.tcc.model.VendaItem;
public class VendaItemDAO extends DAOimpl<VendaItem> {

	private static VendaItemDAO instance;
	
	public static VendaItemDAO getInstance(){
		if(instance == null){
			instance = new VendaItemDAO();
		}
		return instance;
	}
	
	public Collection<VendaItem> getBuscaItensPorVenda( Venda venda) throws Exception {
		Session session = HibernateUtils.getSessionFactory().openSession();
		Transaction t = session.beginTransaction();
		Collection<VendaItem> lista = session.
				createCriteria( VendaItem.class)
				.add( Restrictions.eq( "venda", venda ) )
				.list();
		t.commit();
		return lista;
	}
	
}
